package com.tbocek.android.ode.solver;

import java.util.List;

import com.google.common.collect.Lists;

public class EulerSolver extends Solver {

	@Override
	public List<SystemState> solve(ODESystem system, SystemState initialState,
			float finalTime) {
		SystemState currentState = initialState.copy();
		List<SystemState> result = Lists.newArrayList();
		result.add(currentState);
		
		while (currentState.getTime() <= finalTime) {
			// Midpoint approximation.
			float[] derivs = system.computeDerivatives(currentState);
			currentState = currentState.firstOrderStepForward(
					derivs, deltaT);
			result.add(currentState);
		}
		
		return result;
	}

}
